<template>
  <div>
    <el-table :data="supplierSupplyOfGoodsList">
      <el-table-column prop="user.uname" label="供应商名称"></el-table-column>
      <el-table-column prop="shop.shopName" label="商品名称"></el-table-column>
      <el-table-column prop="shop.type.name" label="商品分类"></el-table-column>
      <el-table-column prop="supplierPrice" label="供应商提供的价格"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="config_t1(scope.row.gid,scope.row.pid)">为商品选择仓库</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageno"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <!--查询等待分配的供应商商品对话框-->
    <el-dialog
      title="等待分配到仓库的供应商商品"
      :visible.sync="t1_Visible"
      width="50%">
      <component ref="designatedWarehouse_T1dialog" is="designatedWarehouse_T1dialog"></component>
      <el-dialog
        width="30%"
        title="请填写仓库详情数据"
        :visible.sync="t2_Visible"
        append-to-body>
        <component ref="designatedWarehouse_T2dialog" is="designatedWarehouse_T2dialog"></component>
        <el-button @click="t2_Visible = false">取 消</el-button>
        <el-button type="primary" @click="config_t2_submit">提交</el-button>
      </el-dialog>
      <div slot="footer" class="dialog-footer">
        <!--填写仓库详情数据的对话框【内层对话框】-->
        <el-button @click="t1_Visible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
    import designatedWarehouse_T1dialog from "./designatedWarehouse_T1dialog";
    import designatedWarehouse_T2dialog from "./designatedWarehouse_T2dialog";
    export default {
        name: "designatedWarehouse",
        data(){
          return {
            supplierId:"",
            shopId:"",
            t1_Visible:false,
            t2_Visible:false,
            supplierSupplyOfGoods:{
              isCheck:1,//审核通过
              isDelete:0//正常供应中
            },
            supplierSupplyOfGoodsList:[],
            pageno: 1,
            pagesize: 5,
            total: 1
          }
        },
        methods:{
          getData(){
            let params=new URLSearchParams();
            params.append("pageno", this.pageno);
            params.append("pagesize", this.pagesize);
            Object.keys(this.supplierSupplyOfGoods).forEach(item=>{
              params.append(item,this.supplierSupplyOfGoods[item]);
            })
            //异步，查询未被删除的商品
            this.$axios.get("supplierSupplyOfGoods/supplierSupplyOfGoods.action",{params:this.supplierSupplyOfGoods}).
            then((response)=> {   //异步调用成功执行
              //将查询到的数据存入对象数组中
              this.supplierSupplyOfGoodsList=response.data.records;
              this.total = response.data.total;
            }).catch(function (error) {//异步调用失败执行
              alert(error);
            });
          },
          config_t1(id,supplierId){
            //将该商品id存入vue对象内
            this.shopId=id;
            //将该供应商id存入vue对象内
            this.supplierId=supplierId;
            //打开对话框
            this.t1_Visible=true;
            //延迟加载，调用异步，查询出该商品id下的，等待配置到仓库、审核通过的、的供应商商品
            this.$nextTick(item=>{
              this.$refs.designatedWarehouse_T1dialog.getData(id);
            })
          },
          config_t2(id){
            //打开对话框
            this.t2_Visible=true;
            //延迟加载，调用子组件函数
            this.$nextTick(item=>{
              this.$refs.designatedWarehouse_T2dialog.getData(id);
            })
          },
          config_t2_submit(){
            //调用子组件函数
            this.$refs.designatedWarehouse_T2dialog.submit();
            //关闭全部对话框
            this.t1_Visible=false;
            this.t2_Visible=false;
            //重新刷新数据
            this.getData();
          },
          handleSizeChange(val) {
            //每页范围
            this.pagesize = val;
            this.getData();
          },
          handleCurrentChange(val) {
            //当前页
            this.pageno = val;
            this.getData();
          }
        },
        created() {
          this.getData();
        },
        components:{
          designatedWarehouse_T1dialog,designatedWarehouse_T2dialog
        }
    }
</script>

<style scoped>

</style>
